package com.tangr.normaladapter.recyclerview;

import android.content.Context;
import android.view.ViewGroup;

import com.tangr.normaladapter.R;
import com.tangr.normaladapter.ViewHolder;

import java.util.List;

/**
 * Created by tangr on 2016/6/8.
 */
public abstract class MultiItemAdapter<T> extends RecyclerAdapter<T>{
    protected MultiItemTypeSupport<T> mMultiItemTypeSupport;
    public MultiItemAdapter(Context mContext, List<T> mList, MultiItemTypeSupport<T> multiItemTypeSupport) {
        super(mContext, mList, -1);
        mMultiItemTypeSupport = multiItemTypeSupport;
        if (mMultiItemTypeSupport == null)
            throw new IllegalArgumentException("the mMultiItemTypeSupport can not be null.");
    }

//    @Override
//    public int getItemViewType(int position) {
//        if (mMultiItemTypeSupport!=null)
//            return mMultiItemTypeSupport.getItemViewType(position, mList.get(position));
//        return super.getItemViewType(position);
//    }

    @Override
    protected int setItemViewType(int position) {
        if (mMultiItemTypeSupport!=null)
            return mMultiItemTypeSupport.getItemViewType(position, mList.get(position));
        return super.getItemViewType(position);
    }

//    @Override
//    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        if(mMultiItemTypeSupport == null)
//            return super.onCreateViewHolder(parent, viewType);
//        int layoutid = mMultiItemTypeSupport.getLayoutId(viewType);
//        ViewHolder viewHolder = ViewHolder.get(mContext, null, parent, layoutid);
//        setListener(parent, viewHolder);
//        return viewHolder;
//    }

    @Override
    public int getLayout(int viewType) {
        if(viewType==HEADER_TYPE)
            return header_layout;
        if(viewType==FOOTER_TYPE)
            return footer_layout;
        if(viewType==LOADMORE_TYPE)
            return R.layout.pull_to_refresh_footer;
        return mMultiItemTypeSupport.getLayoutId(viewType);
    }

    @Override
    public boolean isEnabled(int viewType){
        return mMultiItemTypeSupport.isEnabled(viewType);
    }
}
